<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../header.jsp"%>
<script type="text/javascript">
var passwordValidator;

function changePassword() {
	if (!passwordValidator.form()) {
		return;
	}
	doChangePassword();
}

function doChangePassword() {
	var data = {
			id : $("#userId").val(),
			oldPassword : $("#oldPassword").val(),
			newPassword : $("#userNewPassword").val(),
			newPasswordRetry : $("#userNewPasswordRetry").val()
		};
	
	$.ajax({
		type: "POST",
		url: "/biz/system/user/changePassword.json",
		data: data,
		dataType: "json",
		success: savePasswordSucceedCallback,
		error:function(message){
			$.alert(message);
		}  
	});
}

function savePasswordSucceedCallback(data) {
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}

	//$("#userId").val(data.data.id);
	$.notice("保存成功！");
}

$(document).ready(function() {
	passwordValidator = $("#passwordForm").validate({
		rules: {
			oldPassword:{required:true}, 
			userNewPassword:{required:true},
			userNewPasswordRetry:{required:true,equalTo:"#userNewPassword"}
		},
		messages:{
			oldPassword:{required:"请输入密码"},
			userNewPassword:{required:"请输入密码"},
			userNewPasswordRetry:{required:"请再次输入密码",equalTo: "两次密码输入不一致！"}
		}
	});
	
});

</script>


<div class="border bg">

<div class="page-header">
<h2>修改密码</h2>
</div>

<form id="passwordForm"  class="form-horizontal">
	<fieldset>
	<div class="control-group">
		<label for="oldPassword" class="control-label">旧密码：</label> 
		<div class="controls">
		<input type="password" id="oldPassword" class="required"  name="oldPassword" > <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userNewPassword" class="control-label">新密码：</label> 
		<div class="controls">
		<input type="password" id="userNewPassword" class="required"  name="userNewPassword" > <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userNewPasswordRetry" class="control-label">新密码(再输入一次)：</label>
		<div class="controls">
		<input type="password" id="userNewPasswordRetry" class="required"  name="userNewPasswordRetry" > <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="form-actions">
		<a href="#" class="btn btn-primary" onclick="changePassword()"><i class="icon-ok"></i>保存</a>
	</div>

	</fieldset>
</form>

</div>
<%@ include file="../../../footer.jsp"%>